
#include <stdio.h>
#include <string.h>

#define LEN		10
#define N		100

typedef char str_t[LEN]; 

str_t matrix[N][N]; 
str_t tab[N][N]; 
int   n; 

char	letters[256]; 
char	present[256]; 
char	nr_p = 0; 

int c2n(char c)
{
	return 	c>='0'&&c<='9' ? c-'0' : 
			c>='a'&&c<='z' ? c-'a' + 10 : 
			c>='A'&&c<='Z' ? c-'A' + 10 : 
			-1; 
}

char n2c(int n)
{
	return n<10? n+'0' : n-10+'a'; 
}

void xary_add(int x, char a, char b, char *c_sum, char *c_carry)
{
	int	na, nb; 
	int sum, carry; 
	na = c2n(a); 
	nb = c2n(b); 
	sum = (na + nb) % x; 
	carry = (na + nb) / x; 
	*c_sum = n2c(sum); 
	*c_carry = (carry==0 ? ' ' : n2c(carry)); 
}

void gen_xary_tab(int x)
{
	int	i; 
	int j; 
	char c_sum, c_carry; 
	for (i=0; i<=x; i++) {
		for (j=0; j<=x; j++) {
			if (i==0 && j==0) {
				sprintf(tab[i][j], "+");  
				continue; 
			} 
			if (i==0) {
				sprintf(tab[i][j], "%c", n2c(j-1)); 
				continue; 
			}
			if (j==0) {
				sprintf(tab[i][j], "%c", n2c(i-1)); 
				continue; 
			}
			xary_add(x, n2c(i-1), n2c(j-1), &c_sum, &c_carry); 
			if (c_carry==' ')
				sprintf(tab[i][j], "%c", c_sum); 
			else
				sprintf(tab[i][j], "%c%c", c_carry, c_sum); 
		}
	}
}


int main()
{
	int		i, j, k, c, d; 
	str_t	in; 
	int		al, bl; 
	
	scanf("%d", &n); 
	gen_xary_tab(n-1); 
	for (i=0; i<n; i++) {
		for (j=0; j<n; j++) {
			scanf("%s", in); 
			al = strlen(in); 
			bl = strlen(tab[i][j]); 
			if (al!=bl) {
				printf("ERROR!\n"); 
				return 0; 
			}
			if (i==0 && j==0) 
				continue; 
			for (k=0; k<al; k++) {
				c = in[k]; 
				d = tab[i][j][k]; 
				if (letters[c]==0) {
					letters[c] = d; 
					present[nr_p] = c; 
					nr_p++; 
				} else {
					if (letters[c]!=d) {
						printf("ERROR!\n"); 
						return 0; 
					}
				}
			}
		}
	}
	for (i=0; i<nr_p; i++) {
		printf("%c=%c ", present[i], letters[present[i]]); 
	}
	printf("\n"); 
	printf("%d\n", n-1); 
	return 0; 
}


